package hw726;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class zuoye4 {
	public static void main(String[] args) throws IOException {
		File f1=new File("d:\\abc");
		File f2=new File("d:\\zky");
		
	
		copydir(f1,f2);
		
	}

	private static void copydir(File f1, File f2) throws IOException {
		f2.mkdirs();
		File[] files=f1.listFiles();
		
		if (files != null){
		for(File f:files){
			if(f.isFile()){
				FileInputStream fis=new FileInputStream(f);
				FileOutputStream fos=new FileOutputStream(new File(f2,f.getName()));
				
				byte[] bytes=new byte[1024];
				int len;
				while((len=fis.read(bytes))!=-1){
					fos.write(bytes,0,len);
					
				}
				fos.close();
				fis.close();
				
			}else{
				copydir(f,new File(f2,f.getName()));
			}
		}}
		
		
	}
}
